
import { WebSocket, WebSocketServer } from 'ws';
import { OnModuleInit } from '@nestjs/common';

export class WebsocketGateway implements OnModuleInit{
  private wss: WebSocketServer;
  private currentIndex = 0;
  
  private agentlist: any =  [
    // 原有数据保持不变
    {
      id: '1950832507307249665',
      name: null,
      ip: '127.0.0.1',
      port: 55652,
      mid: 'node001',
      starType: 'lowStar',
      remarks: null,
      status: 1,
      createTime: '2025-07-31 16:14:49',
      updateTime: '2025-09-26 03:10:07',
      heartbeat: '2025-09-25 21:14:45',
      clusterName: null,
      parentMid: 'node002',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249666',
      name: 'TestName',
      ip: '192.168.5.70',
      port: 56495,
      mid: 'node002',
      starType: 'lowStar',
      remarks: null,
      status: 0,
      createTime: '2025-07-31 16:14:49',
      updateTime: '2025-09-26 03:09:49',
      heartbeat: '2025-09-10 14:46:09',
      clusterName: 'karmada集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '192.168.5.70',
      clusterPort: 99,
      clusterStatus: '1',
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // 新增集群主节点
    {
      id: '1950832507307249667',
      name: '生产集群主节点',
      ip: '10.0.1.10',
      port: 8080,
      mid: 'cluster-prod-001',
      starType: 'midStar',
      remarks: '生产环境主集群',
      status: 1,
      createTime: '2025-08-01 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-26 08:15:00',
      clusterName: '生产集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '10.0.1.10',
      clusterPort: 8080,
      clusterStatus: '1',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    {
      id: '1950832507307249668',
      name: '测试集群主节点',
      ip: '10.0.2.10',
      port: 8081,
      mid: 'cluster-test-001',
      starType: 'midStar',
      remarks: '测试环境主集群',
      status: 1,
      createTime: '2025-08-02 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-26 08:16:00',
      clusterName: '测试集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '10.0.2.10',
      clusterPort: 8081,
      clusterStatus: '1',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    {
      id: '1950832507307249669',
      name: '开发集群主节点',
      ip: '10.0.3.10',
      port: 8082,
      mid: 'cluster-dev-001',
      starType: 'lowStar',
      remarks: '开发环境主集群',
      status: 1,
      createTime: '2025-08-03 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-26 08:17:00',
      clusterName: '开发集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '10.0.3.10',
      clusterPort: 8082,
      clusterStatus: '1',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    {
      id: '1950832507307249670',
      name: '预发布集群主节点',
      ip: '10.0.4.10',
      port: 8083,
      mid: 'cluster-pre-001',
      starType: 'midStar',
      remarks: '预发布环境主集群',
      status: 0,
      createTime: '2025-08-04 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-24 15:30:00',
      clusterName: '预发布集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '10.0.4.10',
      clusterPort: 8083,
      clusterStatus: '0',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    {
      id: '1950832507307249671',
      name: '华东区集群主节点',
      ip: '172.16.1.10',
      port: 8084,
      mid: 'cluster-east-001',
      starType: 'midStar',
      remarks: '华东区域主集群',
      status: 1,
      createTime: '2025-08-05 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-26 08:18:00',
      clusterName: '华东区集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '172.16.1.10',
      clusterPort: 8084,
      clusterStatus: '1',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    {
      id: '1950832507307249672',
      name: '华南区集群主节点',
      ip: '172.16.2.10',
      port: 8085,
      mid: 'cluster-south-001',
      starType: 'lowStar',
      remarks: '华南区域主集群',
      status: 1,
      createTime: '2025-08-06 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-26 08:19:00',
      clusterName: '华南区集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '172.16.2.10',
      clusterPort: 8085,
      clusterStatus: '1',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    {
      id: '1950832507307249673',
      name: '华北区集群主节点',
      ip: '172.16.3.10',
      port: 8086,
      mid: 'cluster-north-001',
      starType: 'midStar',
      remarks: '华北区域主集群',
      status: 0,
      createTime: '2025-08-07 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-25 10:30:00',
      clusterName: '华北区集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '172.16.3.10',
      clusterPort: 8086,
      clusterStatus: '0',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    {
      id: '1950832507307249674',
      name: '边缘计算集群主节点',
      ip: '192.168.100.10',
      port: 8087,
      mid: 'cluster-edge-001',
      starType: 'lowStar',
      remarks: '边缘计算主集群',
      status: 1,
      createTime: '2025-08-08 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-26 08:20:00',
      clusterName: '边缘计算集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '192.168.100.10',
      clusterPort: 8087,
      clusterStatus: '1',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    {
      id: '1950832507307249675',
      name: '容灾备份集群主节点',
      ip: '192.168.200.10',
      port: 8088,
      mid: 'cluster-backup-001',
      starType: 'midStar',
      remarks: '容灾备份主集群',
      status: 1,
      createTime: '2025-08-09 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-26 08:21:00',
      clusterName: '容灾备份集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '192.168.200.10',
      clusterPort: 8088,
      clusterStatus: '1',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    {
      id: '1950832507307249676',
      name: 'AI训练集群主节点',
      ip: '192.168.300.10',
      port: 8089,
      mid: 'cluster-ai-001',
      starType: 'midStar',
      remarks: 'AI模型训练主集群',
      status: 1,
      createTime: '2025-08-10 10:00:00',
      updateTime: '2025-09-26 08:00:00',
      heartbeat: '2025-09-26 08:22:00',
      clusterName: 'AI训练集群',
      parentMid: null,
      nodeType: '0',
      clusterIp: '192.168.300.10',
      clusterPort: 8089,
      clusterStatus: '1',
      clusterCreateType: '0',
      clusterCount: '5',
    },
    // 生产集群子节点
    {
      id: '1950832507307249677',
      name: '生产节点1',
      ip: '10.0.1.11',
      port: 55001,
      mid: 'node-prod-001',
      starType: 'lowStar',
      remarks: '生产环境工作节点1',
      status: 1,
      createTime: '2025-08-01 10:30:00',
      updateTime: '2025-09-26 08:01:00',
      heartbeat: '2025-09-26 08:15:30',
      clusterName: null,
      parentMid: 'cluster-prod-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249678',
      name: '生产节点2',
      ip: '10.0.1.12',
      port: 55002,
      mid: 'node-prod-002',
      starType: 'midStar',
      remarks: '生产环境工作节点2',
      status: 1,
      createTime: '2025-08-01 10:31:00',
      updateTime: '2025-09-26 08:01:00',
      heartbeat: '2025-09-26 08:15:31',
      clusterName: null,
      parentMid: 'cluster-prod-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249679',
      name: '生产节点3',
      ip: '10.0.1.13',
      port: 55003,
      mid: 'node-prod-003',
      starType: 'lowStar',
      remarks: '生产环境工作节点3',
      status: 0,
      createTime: '2025-08-01 10:32:00',
      updateTime: '2025-09-26 08:01:00',
      heartbeat: '2025-09-25 20:00:00',
      clusterName: null,
      parentMid: 'cluster-prod-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249680',
      name: '生产节点4',
      ip: '10.0.1.14',
      port: 55004,
      mid: 'node-prod-004',
      starType: 'midStar',
      remarks: '生产环境工作节点4',
      status: 1,
      createTime: '2025-08-01 10:33:00',
      updateTime: '2025-09-26 08:01:00',
      heartbeat: '2025-09-26 08:15:32',
      clusterName: null,
      parentMid: 'cluster-prod-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249681',
      name: '生产节点5',
      ip: '10.0.1.15',
      port: 55005,
      mid: 'node-prod-005',
      starType: 'lowStar',
      remarks: '生产环境工作节点5',
      status: 1,
      createTime: '2025-08-01 10:34:00',
      updateTime: '2025-09-26 08:01:00',
      heartbeat: '2025-09-26 08:15:33',
      clusterName: null,
      parentMid: 'cluster-prod-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // 测试集群子节点
    {
      id: '1950832507307249682',
      name: '测试节点1',
      ip: '10.0.2.11',
      port: 55006,
      mid: 'node-test-001',
      starType: 'midStar',
      remarks: '测试环境工作节点1',
      status: 1,
      createTime: '2025-08-02 10:30:00',
      updateTime: '2025-09-26 08:02:00',
      heartbeat: '2025-09-26 08:16:30',
      clusterName: null,
      parentMid: 'cluster-test-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249683',
      name: '测试节点2',
      ip: '10.0.2.12',
      port: 55007,
      mid: 'node-test-002',
      starType: 'lowStar',
      remarks: '测试环境工作节点2',
      status: 1,
      createTime: '2025-08-02 10:31:00',
      updateTime: '2025-09-26 08:02:00',
      heartbeat: '2025-09-26 08:16:31',
      clusterName: null,
      parentMid: 'cluster-test-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249684',
      name: '测试节点3',
      ip: '10.0.2.13',
      port: 55008,
      mid: 'node-test-003',
      starType: 'midStar',
      remarks: '测试环境工作节点3',
      status: 0,
      createTime: '2025-08-02 10:32:00',
      updateTime: '2025-09-26 08:02:00',
      heartbeat: '2025-09-24 16:00:00',
      clusterName: null,
      parentMid: 'cluster-test-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249685',
      name: '测试节点4',
      ip: '10.0.2.14',
      port: 55009,
      mid: 'node-test-004',
      starType: 'lowStar',
      remarks: '测试环境工作节点4',
      status: 1,
      createTime: '2025-08-02 10:33:00',
      updateTime: '2025-09-26 08:02:00',
      heartbeat: '2025-09-26 08:16:32',
      clusterName: null,
      parentMid: 'cluster-test-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249686',
      name: '测试节点5',
      ip: '10.0.2.15',
      port: 55010,
      mid: 'node-test-005',
      starType: 'midStar',
      remarks: '测试环境工作节点5',
      status: 1,
      createTime: '2025-08-02 10:34:00',
      updateTime: '2025-09-26 08:02:00',
      heartbeat: '2025-09-26 08:16:33',
      clusterName: null,
      parentMid: 'cluster-test-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // 开发集群子节点
    {
      id: '1950832507307249687',
      name: '开发节点1',
      ip: '10.0.3.11',
      port: 55011,
      mid: 'node-dev-001',
      starType: 'lowStar',
      remarks: '开发环境工作节点1',
      status: 1,
      createTime: '2025-08-03 10:30:00',
      updateTime: '2025-09-26 08:03:00',
      heartbeat: '2025-09-26 08:17:30',
      clusterName: null,
      parentMid: 'cluster-dev-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249688',
      name: '开发节点2',
      ip: '10.0.3.12',
      port: 55012,
      mid: 'node-dev-002',
      starType: 'midStar',
      remarks: '开发环境工作节点2',
      status: 1,
      createTime: '2025-08-03 10:31:00',
      updateTime: '2025-09-26 08:03:00',
      heartbeat: '2025-09-26 08:17:31',
      clusterName: null,
      parentMid: 'cluster-dev-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249689',
      name: '开发节点3',
      ip: '10.0.3.13',
      port: 55013,
      mid: 'node-dev-003',
      starType: 'lowStar',
      remarks: '开发环境工作节点3',
      status: 0,
      createTime: '2025-08-03 10:32:00',
      updateTime: '2025-09-26 08:03:00',
      heartbeat: '2025-09-25 14:00:00',
      clusterName: null,
      parentMid: 'cluster-dev-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249690',
      name: '开发节点4',
      ip: '10.0.3.14',
      port: 55014,
      mid: 'node-dev-004',
      starType: 'midStar',
      remarks: '开发环境工作节点4',
      status: 1,
      createTime: '2025-08-03 10:33:00',
      updateTime: '2025-09-26 08:03:00',
      heartbeat: '2025-09-26 08:17:32',
      clusterName: null,
      parentMid: 'cluster-dev-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249691',
      name: '开发节点5',
      ip: '10.0.3.15',
      port: 55015,
      mid: 'node-dev-005',
      starType: 'lowStar',
      remarks: '开发环境工作节点5',
      status: 1,
      createTime: '2025-08-03 10:34:00',
      updateTime: '2025-09-26 08:03:00',
      heartbeat: '2025-09-26 08:17:33',
      clusterName: null,
      parentMid: 'cluster-dev-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // 预发布集群子节点
    {
      id: '1950832507307249692',
      name: '预发布节点1',
      ip: '10.0.4.11',
      port: 55016,
      mid: 'node-pre-001',
      starType: 'midStar',
      remarks: '预发布环境工作节点1',
      status: 0,
      createTime: '2025-08-04 10:30:00',
      updateTime: '2025-09-26 08:04:00',
      heartbeat: '2025-09-24 15:30:00',
      clusterName: null,
      parentMid: 'cluster-pre-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249693',
      name: '预发布节点2',
      ip: '10.0.4.12',
      port: 55017,
      mid: 'node-pre-002',
      starType: 'lowStar',
      remarks: '预发布环境工作节点2',
      status: 0,
      createTime: '2025-08-04 10:31:00',
      updateTime: '2025-09-26 08:04:00',
      heartbeat: '2025-09-24 15:31:00',
      clusterName: null,
      parentMid: 'cluster-pre-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249694',
      name: '预发布节点3',
      ip: '10.0.4.13',
      port: 55018,
      mid: 'node-pre-003',
      starType: 'midStar',
      remarks: '预发布环境工作节点3',
      status: 1,
      createTime: '2025-08-04 10:32:00',
      updateTime: '2025-09-26 08:04:00',
      heartbeat: '2025-09-26 08:18:30',
      clusterName: null,
      parentMid: 'cluster-pre-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249695',
      name: '预发布节点4',
      ip: '10.0.4.14',
      port: 55019,
      mid: 'node-pre-004',
      starType: 'lowStar',
      remarks: '预发布环境工作节点4',
      status: 0,
      createTime: '2025-08-04 10:33:00',
      updateTime: '2025-09-26 08:04:00',
      heartbeat: '2025-09-24 15:32:00',
      clusterName: null,
      parentMid: 'cluster-pre-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249696',
      name: '预发布节点5',
      ip: '10.0.4.15',
      port: 55020,
      mid: 'node-pre-005',
      starType: 'midStar',
      remarks: '预发布环境工作节点5',
      status: 0,
      createTime: '2025-08-04 10:34:00',
      updateTime: '2025-09-26 08:04:00',
      heartbeat: '2025-09-24 15:33:00',
      clusterName: null,
      parentMid: 'cluster-pre-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // 华东区集群子节点
    {
      id: '1950832507307249697',
      name: '华东节点1',
      ip: '172.16.1.11',
      port: 55021,
      mid: 'node-east-001',
      starType: 'lowStar',
      remarks: '华东区域工作节点1',
      status: 1,
      createTime: '2025-08-05 10:30:00',
      updateTime: '2025-09-26 08:05:00',
      heartbeat: '2025-09-26 08:18:30',
      clusterName: null,
      parentMid: 'cluster-east-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249698',
      name: '华东节点2',
      ip: '172.16.1.12',
      port: 55022,
      mid: 'node-east-002',
      starType: 'midStar',
      remarks: '华东区域工作节点2',
      status: 1,
      createTime: '2025-08-05 10:31:00',
      updateTime: '2025-09-26 08:05:00',
      heartbeat: '2025-09-26 08:18:31',
      clusterName: null,
      parentMid: 'cluster-east-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249699',
      name: '华东节点3',
      ip: '172.16.1.13',
      port: 55023,
      mid: 'node-east-003',
      starType: 'lowStar',
      remarks: '华东区域工作节点3',
      status: 1,
      createTime: '2025-08-05 10:32:00',
      updateTime: '2025-09-26 08:05:00',
      heartbeat: '2025-09-26 08:18:32',
      clusterName: null,
      parentMid: 'cluster-east-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249700',
      name: '华东节点4',
      ip: '172.16.1.14',
      port: 55024,
      mid: 'node-east-004',
      starType: 'midStar',
      remarks: '华东区域工作节点4',
      status: 0,
      createTime: '2025-08-05 10:33:00',
      updateTime: '2025-09-26 08:05:00',
      heartbeat: '2025-09-25 12:00:00',
      clusterName: null,
      parentMid: 'cluster-east-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249701',
      name: '华东节点5',
      ip: '172.16.1.15',
      port: 55025,
      mid: 'node-east-005',
      starType: 'lowStar',
      remarks: '华东区域工作节点5',
      status: 1,
      createTime: '2025-08-05 10:34:00',
      updateTime: '2025-09-26 08:05:00',
      heartbeat: '2025-09-26 08:18:33',
      clusterName: null,
      parentMid: 'cluster-east-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // 华南区集群子节点
    {
      id: '1950832507307249702',
      name: '华南节点1',
      ip: '172.16.2.11',
      port: 55026,
      mid: 'node-south-001',
      starType: 'midStar',
      remarks: '华南区域工作节点1',
      status: 1,
      createTime: '2025-08-06 10:30:00',
      updateTime: '2025-09-26 08:06:00',
      heartbeat: '2025-09-26 08:19:30',
      clusterName: null,
      parentMid: 'cluster-south-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249703',
      name: '华南节点2',
      ip: '172.16.2.12',
      port: 55027,
      mid: 'node-south-002',
      starType: 'lowStar',
      remarks: '华南区域工作节点2',
      status: 1,
      createTime: '2025-08-06 10:31:00',
      updateTime: '2025-09-26 08:06:00',
      heartbeat: '2025-09-26 08:19:31',
      clusterName: null,
      parentMid: 'cluster-south-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249704',
      name: '华南节点3',
      ip: '172.16.2.13',
      port: 55028,
      mid: 'node-south-003',
      starType: 'midStar',
      remarks: '华南区域工作节点3',
      status: 0,
      createTime: '2025-08-06 10:32:00',
      updateTime: '2025-09-26 08:06:00',
      heartbeat: '2025-09-24 18:00:00',
      clusterName: null,
      parentMid: 'cluster-south-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249705',
      name: '华南节点4',
      ip: '172.16.2.14',
      port: 55029,
      mid: 'node-south-004',
      starType: 'lowStar',
      remarks: '华南区域工作节点4',
      status: 1,
      createTime: '2025-08-06 10:33:00',
      updateTime: '2025-09-26 08:06:00',
      heartbeat: '2025-09-26 08:19:32',
      clusterName: null,
      parentMid: 'cluster-south-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249706',
      name: '华南节点5',
      ip: '172.16.2.15',
      port: 55030,
      mid: 'node-south-005',
      starType: 'midStar',
      remarks: '华南区域工作节点5',
      status: 1,
      createTime: '2025-08-06 10:34:00',
      updateTime: '2025-09-26 08:06:00',
      heartbeat: '2025-09-26 08:19:33',
      clusterName: null,
      parentMid: 'cluster-south-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // 华北区集群子节点
    {
      id: '1950832507307249707',
      name: '华北节点1',
      ip: '172.16.3.11',
      port: 55031,
      mid: 'node-north-001',
      starType: 'lowStar',
      remarks: '华北区域工作节点1',
      status: 0,
      createTime: '2025-08-07 10:30:00',
      updateTime: '2025-09-26 08:07:00',
      heartbeat: '2025-09-25 10:30:00',
      clusterName: null,
      parentMid: 'cluster-north-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249708',
      name: '华北节点2',
      ip: '172.16.3.12',
      port: 55032,
      mid: 'node-north-002',
      starType: 'midStar',
      remarks: '华北区域工作节点2',
      status: 0,
      createTime: '2025-08-07 10:31:00',
      updateTime: '2025-09-26 08:07:00',
      heartbeat: '2025-09-25 10:31:00',
      clusterName: null,
      parentMid: 'cluster-north-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249709',
      name: '华北节点3',
      ip: '172.16.3.13',
      port: 55033,
      mid: 'node-north-003',
      starType: 'lowStar',
      remarks: '华北区域工作节点3',
      status: 1,
      createTime: '2025-08-07 10:32:00',
      updateTime: '2025-09-26 08:07:00',
      heartbeat: '2025-09-26 08:20:30',
      clusterName: null,
      parentMid: 'cluster-north-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249710',
      name: '华北节点4',
      ip: '172.16.3.14',
      port: 55034,
      mid: 'node-north-004',
      starType: 'midStar',
      remarks: '华北区域工作节点4',
      status: 0,
      createTime: '2025-08-07 10:33:00',
      updateTime: '2025-09-26 08:07:00',
      heartbeat: '2025-09-25 10:32:00',
      clusterName: null,
      parentMid: 'cluster-north-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249711',
      name: '华北节点5',
      ip: '172.16.3.15',
      port: 55035,
      mid: 'node-north-005',
      starType: 'lowStar',
      remarks: '华北区域工作节点5',
      status: 0,
      createTime: '2025-08-07 10:34:00',
      updateTime: '2025-09-26 08:07:00',
      heartbeat: '2025-09-25 10:33:00',
      clusterName: null,
      parentMid: 'cluster-north-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // 边缘计算集群子节点
    {
      id: '1950832507307249712',
      name: '边缘节点1',
      ip: '192.168.100.11',
      port: 55036,
      mid: 'node-edge-001',
      starType: 'midStar',
      remarks: '边缘计算工作节点1',
      status: 1,
      createTime: '2025-08-08 10:30:00',
      updateTime: '2025-09-26 08:08:00',
      heartbeat: '2025-09-26 08:20:30',
      clusterName: null,
      parentMid: 'cluster-edge-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249713',
      name: '边缘节点2',
      ip: '192.168.100.12',
      port: 55037,
      mid: 'node-edge-002',
      starType: 'lowStar',
      remarks: '边缘计算工作节点2',
      status: 1,
      createTime: '2025-08-08 10:31:00',
      updateTime: '2025-09-26 08:08:00',
      heartbeat: '2025-09-26 08:20:31',
      clusterName: null,
      parentMid: 'cluster-edge-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249714',
      name: '边缘节点3',
      ip: '192.168.100.13',
      port: 55038,
      mid: 'node-edge-003',
      starType: 'midStar',
      remarks: '边缘计算工作节点3',
      status: 0,
      createTime: '2025-08-08 10:32:00',
      updateTime: '2025-09-26 08:08:00',
      heartbeat: '2025-09-25 16:00:00',
      clusterName: null,
      parentMid: 'cluster-edge-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249715',
      name: '边缘节点4',
      ip: '192.168.100.14',
      port: 55039,
      mid: 'node-edge-004',
      starType: 'lowStar',
      remarks: '边缘计算工作节点4',
      status: 1,
      createTime: '2025-08-08 10:33:00',
      updateTime: '2025-09-26 08:08:00',
      heartbeat: '2025-09-26 08:20:32',
      clusterName: null,
      parentMid: 'cluster-edge-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249716',
      name: '边缘节点5',
      ip: '192.168.100.15',
      port: 55040,
      mid: 'node-edge-005',
      starType: 'midStar',
      remarks: '边缘计算工作节点5',
      status: 1,
      createTime: '2025-08-08 10:34:00',
      updateTime: '2025-09-26 08:08:00',
      heartbeat: '2025-09-26 08:20:33',
      clusterName: null,
      parentMid: 'cluster-edge-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // 容灾备份集群子节点
    {
      id: '1950832507307249717',
      name: '备份节点1',
      ip: '192.168.200.11',
      port: 55041,
      mid: 'node-backup-001',
      starType: 'lowStar',
      remarks: '容灾备份工作节点1',
      status: 1,
      createTime: '2025-08-09 10:30:00',
      updateTime: '2025-09-26 08:09:00',
      heartbeat: '2025-09-26 08:21:30',
      clusterName: null,
      parentMid: 'cluster-backup-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249718',
      name: '备份节点2',
      ip: '192.168.200.12',
      port: 55042,
      mid: 'node-backup-002',
      starType: 'midStar',
      remarks: '容灾备份工作节点2',
      status: 1,
      createTime: '2025-08-09 10:31:00',
      updateTime: '2025-09-26 08:09:00',
      heartbeat: '2025-09-26 08:21:31',
      clusterName: null,
      parentMid: 'cluster-backup-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249719',
      name: '备份节点3',
      ip: '192.168.200.13',
      port: 55043,
      mid: 'node-backup-003',
      starType: 'lowStar',
      remarks: '容灾备份工作节点3',
      status: 1,
      createTime: '2025-08-09 10:32:00',
      updateTime: '2025-09-26 08:09:00',
      heartbeat: '2025-09-26 08:21:32',
      clusterName: null,
      parentMid: 'cluster-backup-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249720',
      name: '备份节点4',
      ip: '192.168.200.14',
      port: 55044,
      mid: 'node-backup-004',
      starType: 'midStar',
      remarks: '容灾备份工作节点4',
      status: 0,
      createTime: '2025-08-09 10:33:00',
      updateTime: '2025-09-26 08:09:00',
      heartbeat: '2025-09-25 20:00:00',
      clusterName: null,
      parentMid: 'cluster-backup-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249721',
      name: '备份节点5',
      ip: '192.168.200.15',
      port: 55045,
      mid: 'node-backup-005',
      starType: 'lowStar',
      remarks: '容灾备份工作节点5',
      status: 1,
      createTime: '2025-08-09 10:34:00',
      updateTime: '2025-09-26 08:09:00',
      heartbeat: '2025-09-26 08:21:33',
      clusterName: null,
      parentMid: 'cluster-backup-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    // AI训练集群子节点
    {
      id: '1950832507307249722',
      name: 'AI训练节点1',
      ip: '192.168.300.11',
      port: 55046,
      mid: 'node-ai-001',
      starType: 'midStar',
      remarks: 'AI模型训练工作节点1',
      status: 1,
      createTime: '2025-08-10 10:30:00',
      updateTime: '2025-09-26 08:10:00',
      heartbeat: '2025-09-26 08:22:30',
      clusterName: null,
      parentMid: 'cluster-ai-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249723',
      name: 'AI训练节点2',
      ip: '192.168.300.12',
      port: 55047,
      mid: 'node-ai-002',
      starType: 'lowStar',
      remarks: 'AI模型训练工作节点2',
      status: 1,
      createTime: '2025-08-10 10:31:00',
      updateTime: '2025-09-26 08:10:00',
      heartbeat: '2025-09-26 08:22:31',
      clusterName: null,
      parentMid: 'cluster-ai-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249724',
      name: 'AI训练节点3',
      ip: '192.168.300.13',
      port: 55048,
      mid: 'node-ai-003',
      starType: 'midStar',
      remarks: 'AI模型训练工作节点3',
      status: 1,
      createTime: '2025-08-10 10:32:00',
      updateTime: '2025-09-26 08:10:00',
      heartbeat: '2025-09-26 08:22:32',
      clusterName: null,
      parentMid: 'cluster-ai-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249725',
      name: 'AI训练节点4',
      ip: '192.168.300.14',
      port: 55049,
      mid: 'node-ai-004',
      starType: 'lowStar',
      remarks: 'AI模型训练工作节点4',
      status: 0,
      createTime: '2025-08-10 10:33:00',
      updateTime: '2025-09-26 08:10:00',
      heartbeat: '2025-09-25 22:00:00',
      clusterName: null,
      parentMid: 'cluster-ai-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
    {
      id: '1950832507307249726',
      name: 'AI训练节点5',
      ip: '192.168.300.15',
      port: 55050,
      mid: 'node-ai-005',
      starType: 'midStar',
      remarks: 'AI模型训练工作节点5',
      status: 1,
      createTime: '2025-08-10 10:34:00',
      updateTime: '2025-09-26 08:10:00',
      heartbeat: '2025-09-26 08:22:33',
      clusterName: null,
      parentMid: 'cluster-ai-001',
      nodeType: '1',
      clusterIp: null,
      clusterPort: null,
      clusterStatus: null,
      clusterCreateType: '0',
      clusterCount: '0',
    },
  ]


  onModuleInit(){
    this.wss = new WebSocket.Server({ port: 18101});
    this.wss.on('connection', (ws: WebSocket) => {
      this.startDataPush(ws);
    })
  }

  private startDataPush(client: WebSocket) {
    const interval = setInterval(() => {
      if (client.readyState === WebSocket.OPEN) {
        // 获取当前agent
        this.currentIndex++
        if(this.currentIndex>=this.agentlist.length){
          this.currentIndex = 0;
        }
        const currentAgent = this.agentlist[this.currentIndex];
        // 生成总的资源
        const totalCpuAllocatable = Math.floor(Math.random() * 50) + 50; // 50-100
        const totalMemoryAllocatable = Math.floor(Math.random() * 50) + 50; // 50-100
        const totalDiskAllocatable = Math.floor(Math.random() * 50) + 50; // 50-100
        const totalPodsAllocatable = Math.floor(Math.random() * 100) + 100; // 100-200
        
        // 生成使用的资源(不超过总的)
        const totalCpuUsage = Math.floor(Math.random() * totalCpuAllocatable);
        const totalMemoryUsage = Math.floor(Math.random() * totalMemoryAllocatable);
        const totalDiskUsage = Math.floor(Math.random() * totalDiskAllocatable);
        const totalPodsUsage = Math.floor(Math.random() * totalPodsAllocatable);
        
        // 计算使用率
        const totalCpuUsagePercent = ((totalCpuUsage / totalCpuAllocatable) * 100).toFixed(2);
        const totalMemoryUsagePercent = ((totalMemoryUsage / totalMemoryAllocatable) * 100).toFixed(2);
        const totalDiskUsagePercent = ((totalDiskUsage / totalDiskAllocatable) * 100).toFixed(2);
        const totalPodsUsagePercent = ((totalPodsUsage / totalPodsAllocatable) * 100).toFixed(2);

        client.send(JSON.stringify({
          type: '15',
          data: {
            agentId: currentAgent.id,
            data: {
              totalCpuAllocatable: totalCpuAllocatable.toString(),
              totalMemoryAllocatable: totalMemoryAllocatable.toString(),
              totalDiskAllocatable: totalDiskAllocatable.toString(),
              totalPodsAllocatable: totalPodsAllocatable.toString(),
              totalCpuUsage: totalCpuUsage.toString(),
              totalMemoryUsage: totalMemoryUsage.toString(),
              totalDiskUsage: totalDiskUsage.toString(),
              totalPodsUsage: totalPodsUsage.toString(),
              totalCpuUsagePercent: totalCpuUsagePercent + "%",
              totalMemoryUsagePercent: totalMemoryUsagePercent + "%",
              totalDiskUsagePercent: totalDiskUsagePercent + "%",
              totalPodsUsagePercent: totalPodsUsagePercent + "%"
            }
          },
        }));
      } else {
        clearInterval(interval);
      }
    }, 5000);

    client.on('close', () => {
      clearInterval(interval);
    });
  }
}
